﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Permission>" %>
<%@ Import Namespace="Ornament.Web" %>
<%@ Import Namespace="Ornament.MemberShip.Permissions" %>
<%
    var resources = OrnamentContext.Current.MemberShipFactory
                  .CreateResourceDao().GetResourceByType(typeof(GenericResourceInfo<string>));
    var sameType = this.Model.Resource != null && this.Model.Resource.GetType() == typeof(GenericResourceInfo<string>);
    
%>
<%
    int resourcesIndex = 0;
    bool checkedIt = false;
    foreach (var resourceInfo in resources)
    {
        //当原来的资源类型和新选择的资源，不同的时候，那么默认选择第一个。
        

        if (resourcesIndex == 0 && !sameType)
        {
            checkedIt = true;
        }
        else if (sameType)
        {
            checkedIt = this.Model.Resource.Id == resourceInfo.Id;
        }


%>
<div>
    <input type="radio" value="<%=resourceInfo.Id %>" id="<%=resourceInfo.Id%>" name="resourceId"
        <%=checkedIt?"checked='checked'":""%> />
    <label for="<%=resourceInfo.Id%>">
        <%=resourceInfo.Name %></label>
</div>
<%
    resourcesIndex++;
    } %>
